package com.zsc.edu.testfragment;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 这个布局静态加载 Fragment
        //setContentView(R.layout.activity_main);
        // 这个布局动态加载 Fragment
        setContentView(R.layout.activity_main_fragment);

        // 初始化 MyFragment
        MyFragment myFragment = new MyFragment();
        // 获得管理器
        FragmentManager fragmentManager = getSupportFragmentManager();
        // begin  transaction
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        // 添加碎片
        fragmentTransaction.add(R.id.framelayout, myFragment);
        // 提交事务
        fragmentTransaction.commit();

    }
}